<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/7
 * Time: 14:05
 */

namespace app\common\model;


use think\Model;

class CarAuth extends Model
{
    protected $name = "car_auth";
    public function getUserCarInfoList ($where, $field, $request,$keyword) {

        if ($keyword) {
            $list = $this->alias('ca')
                ->join('user_auth ua', 'ca.user_id = ua.user_id', 'left')
                ->where($where)
//                ->whereOr("ca.user_id",$keyword)
//                ->whereOr("ca.phone",$keyword)
//                ->whereOr("ca.name",$keyword)
//                ->whereOr("ca.id",$keyword)
                ->whereOr('ca.user_id|ca.phone|ca.id|ca.name','like',"%$keyword%")
                ->field($field)
                ->order('ca.create_time desc')
                ->paginate(20, false, ['query' => $request->get()]);
        } else {
            $list = $this->alias('ca')
                ->join('user_auth ua', 'ca.user_id = ua.user_id', 'left')
                ->where($where)
                ->field($field)
                ->order('ca.create_time desc')
                ->paginate(20, false, ['query' => $request->get()]);
        }


        return $list;

    }

    public function getUserCarInfo ($where, $field) {

        $data = $this->alias('ca')
            ->join('user_auth ua', 'ca.user_id = ua.user_id', 'left')
            ->where($where)
            ->field($field)
            ->find();

        return $data;
    }
}